﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.BLL;

public partial class admin_AddEditUser : PageBase
{
    private int id;
    private static bool isAdd = false;
    private static Maticsoft.Model.userinfo userModel;
    private Maticsoft.BLL.userinfo bllUser = new Maticsoft.BLL.userinfo();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            id = Convert.ToInt32(Request["id"]);
            if (!string.IsNullOrEmpty(id + ""))
            {
                isAdd = false;
                userModel = bllUser.GetModel(id);
                txtName.Value = userModel.username;
                if (userModel.State == 0)
                {
                    qiyong.Checked = true;
                }
                else
                {
                    jinyong.Checked = true;
                }
            }
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (userModel != null)
        {
            Maticsoft.Model.userinfo loginUser = Session["loginUser"] as Maticsoft.Model.userinfo;
            userModel.username = txtName.Value;
            if (jinyong.Checked)
            {
                userModel.State = 1;
            }
            else if (qiyong.Checked)
            {
                userModel.State = 0;
            }
            userModel.ModifiedTime = DateTime.Now;
            int result = 0;
            if (!isAdd)
            {
                userModel.ModifiedBy = loginUser.Id;
                result = bllUser.Update(userModel) ? 1 : 0;
            }
            else
            {
                userModel.CreatedDate = DateTime.Now;
                userModel.CreatedBy = loginUser.Id;
                result = bllUser.Add(userModel);
            }
            if (result > 0)
            {
                AlertClass.ShowAlert("更改成功");
            }
        }


    }
}